ifeq ($(strip $(COMPILER)),clang)
CC = clang
AR = llvm-ar cru
RANLIB = llvm-ranlib
else
CC = $(strip $(CROSS_COMPILE))gcc
AR = $(strip $(CROSS_COMPILE))ar cru
RANLIB = $(strip $(CROSS_COMPILE))ranlib
endif

export COMPATIBAL_CHIP
export chipname

chipname = $(strip $(CHIPNAME))

ifeq (goldengate2, $(filter goldengate2, $(chipname)))
else
ifeq (goldengate, $(filter goldengate, $(chipname)))
COMPATIBAL_CHIP += goldengate
endif
endif
ifeq (greatbelt, $(filter greatbelt, $(chipname)))
COMPATIBAL_CHIP += greatbelt
endif

ifeq ($(strip $(COMPILER)),clang)
CPPFLAGS += -DCLANG
endif

ifneq ($(findstring HOST_IS_LE, $(CTC_CFLAGS)),HOST_IS_LE)
ifeq ($(strip $(ARCH)),powerpc)
CPPFLAGS += -DHOST_IS_LE=0
CPPFLAGS += -DCTC_ARCH_PPC
endif

ifeq ($(strip $(ARCH)),x86)
CPPFLAGS += -DHOST_IS_LE=1
CPPFLAGS += -DCTC_ARCH_X86
endif

ifeq ($(strip $(ARCH)),mips)
ifeq ($(strip $(CPU)),ls2f)
CPPFLAGS += -DHOST_IS_LE=1
else
CPPFLAGS += -DHOST_IS_LE=0
endif
CPPFLAGS += -DCTC_ARCH_MIPS
endif

ifeq ($(strip $(ARCH)),freescale)
CPPFLAGS += -DHOST_IS_LE=0
CPPFLAGS += -DCTC_ARCH_PPC
endif

ifeq ($(strip $(ARCH)),arm)
CPPFLAGS += -DHOST_IS_LE=1
CPPFLAGS += -DCTC_ARCH_ARM
endif

ifeq ($(strip $(ARCH)),arm64)
CPPFLAGS += -DHOST_IS_LE=1
CPPFLAGS += -DCTC_ARCH_ARM64
endif

ifeq ($(strip $(ARCH)),um)
CPPFLAGS += -DHOST_IS_LE=1
endif
endif

ifeq ($(strip $(ARCH)),mips)
ifeq ($(strip $(CPU)),ls2f)

else
CPPFLAGS += -mabi=n32
endif
endif

ifeq ($(strip $(CPU)),ls2f)
ifneq ($(strip $(M64)),TRUE)
CPPFLAGS += -DDAL_USE_MMAP2
endif
endif

#################################
#SDK_WORK_ENV
#0 - with no cmodel;
#1 - with  cmodel;
#################################

#################################
#SDK_WORK_PLATFORM
#0 - hardware platform ;
#1 - software simulation platform;
#################################

ifeq ($(strip $(BOARD)),ctc-sim)
CPPFLAGS += -DSDK_IN_USERMODE
CPPFLAGS += -DUSE_SIM_MEM
CPPFLAGS += -DSDK_WORK_ENV=1
CPPFLAGS += -DSDK_WORK_PLATFORM=1
ifeq ($(strip $(VER)),d)
RPATH += $(LIB_DIR)
else
ifeq ($(strip $(M64)),TRUE)
RPATH += /data01/users/sdk/humber_release/share/dll_x64/$(chipname)
else
RPATH += /data01/users/sdk/humber_release/share/dll/$(chipname)
endif
endif
endif

ifeq ($(strip $(BOARD)),linux-board)
CPPFLAGS += -DSDK_IN_USERMODE
CPPFLAGS += -DSDK_WORK_PLATFORM=0
CPPFLAGS += -DSDK_WORK_ENV=0
endif	

ifeq ($(strip $(M64)),TRUE)
ifeq ($(strip $(ARCH)),freescale)
CPPFLAGS += -fPIC -Wno-long-long -Wformat
endif
ifeq ($(strip $(ARCH)), arm64)
CPPFLAGS += -fPIC -Wno-long-long -Wformat
else
LD_FLAGS += -m64
CPPFLAGS += -fPIC -Wno-long-long -Wformat -m64
endif
else
ifeq ($(strip $(CPU)),ls2f)
LD_FLAGS += -mabi=n32
else
ifneq ($(strip $(ARCH)),arm)
CPPFLAGS += -m32
LD_FLAGS += -m32
endif
endif
endif

ifneq ($(strip $(VER)),r)
CPPFLAGS += -DSDK_IN_DEBUG_VER
endif

CFLAGS += -fno-strict-aliasing

IS_GCOV = no

ifeq ($(strip $(IS_GCOV)),yes)
CPPFLAGS += -DISGCOV
endif


ifeq (l2, $(filter l2, $(strip $(featureMode))))
CPPFLAGS += -DFEATURE_MODE=1
else
	ifeq (l2l3, $(filter l2l3, $(strip $(featureMode))))
	CPPFLAGS += -DFEATURE_MODE=2
	else
	CPPFLAGS += -DFEATURE_MODE=0
	endif
endif

ifeq (greatbelt, $(filter greatbelt, $(chipname)))
CPPFLAGS += -DGREATBELT
endif

ifeq (goldengate, $(filter goldengate, $(chipname)))
CPPFLAGS += -DGOLDENGATE
endif

ifeq (duet2, $(filter duet2, $(chipname)))
CPPFLAGS += -DDUET2
endif

ifeq (arctic, $(filter arctic, $(chipname)))
CPPFLAGS += -DARCTIC
endif

ifeq (tsingma_gx, $(filter tsingma_gx, $(chipname)))
CPPFLAGS += -DTSINGMA_GX
endif
ifeq (tsingma_mx, $(filter tsingma_mx, $(chipname)))
CPPFLAGS += -DTSINGMA_MX
endif

ifeq (tsingma, $(filter tsingma, $(chipname)))
CPPFLAGS += -DTSINGMA
endif

ifeq (tsingma_ax, $(filter tsingma_ax, $(chipname)))
CPPFLAGS += -DTSINGMA_AX
endif
ifeq ($(strip $(EUNIT)), yes)
CPPFLAGS += -DE_UNIT
endif

#RELEASE_DELETE_START
ifeq ($(strip $(chipname)), arctic)
ifeq ($(strip $(BOARD)),ctc-sim)
eunit_sim = yes
else
eunit_sim = no
endif
endif

ifeq ($(strip $(eunit_sim)), yes)
CPPFLAGS += -DEUNIT_SIM
endif
#RELEASE_DELETE_END

ifdef SDB_MODE
CTC_CFLAGS += -DSDB_MODE=$(SDB_MODE)
else
ifeq (tsingma_mx, $(filter tsingma_mx, $(chipname)))
CTC_CFLAGS += -DSDB_MODE=1
else
CTC_CFLAGS += -DSDB_MODE=0
endif
endif

ifeq ($(strip $(MCHIP_SIM)), yes)
ifeq ($(strip $(BOARD)),linux-board)
CTC_CFLAGS += -DMCHIP_SIM=1
else
CTC_CFLAGS += -DMCHIP_SIM=0
endif
else
CTC_CFLAGS += -DMCHIP_SIM=0
endif

CFLAGS += $(CTC_CFLAGS)
#CFLAGS += -Wframe-larger-than=1024

ifeq ($(strip $(PUMP)), TRUE)
CPPFLAGS += -DCTC_PUMP
endif

ifeq ($(CTC_SAMPLE), TRUE)
CPPFLAGS += -DCTC_SAMPLE
endif

ifeq ($(CTC_PHY_EN), yes)
CPPFLAGS += -DCTC_PHY_EN
CPPFLAGS += -DCTC_MULTI_CLIENT_EN
endif

ifeq ($(CTC_CLI_EN), yes)
CPPFLAGS += -DCTC_CLI_EN
endif
ifeq ($(ASW_ALONE), yes)
CPPFLAGS += -DASW_ALONE
endif
